package com.valveinspectionsys.routing.activity;

import com.valveinspectionsys.R;
import com.valveinspectionsys.dbhelp.XmlNameHelper;
import com.valveinspectionsys.povo.SpinnerVo;
import com.valveinspectionsys.routing.db.DeviceRoutingDao;
import com.valveinspectionsys.util.SharedPreferenceUtil;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;

/**
 * 条件查询
 * @author King
 *
 */
public class DeviceRoutingConditionActivity extends Activity {
     
    public EditText  edit1;//设备编号
    
    public Spinner  edit2;//设备类型
    
    public EditText  edit3;//设备地址
    
    public Spinner  spinner1;//设备册
    
    public Button  button;//查询
    
    public Spinner  spinner;//设备状态
    
     private  String  devicestatus="请选择";
     
     private String deviceType="请选择";
     
     private String deviceListid;//设备册ID
     
     
     private SharedPreferenceUtil sp;
     
     private DeviceRoutingDao  dao;
     
  
    @Override
    protected void onCreate(Bundle savedInstanceState) {
	
	super.onCreate(savedInstanceState);
	setContentView(R.layout.device_query_condition);
	sp=new SharedPreferenceUtil(this);
	dao=new DeviceRoutingDao(this, sp.getValue(XmlNameHelper.SqliteName));
	edit1=(EditText)findViewById(R.id.device_query_condition_number);
	edit2=(Spinner)findViewById(R.id.device_query_condition_devicename);
	edit3=(EditText)findViewById(R.id.device_query_condition_deviceadds);
	spinner=(Spinner)findViewById(R.id.device_query_condition_devicestatus);
	button=(Button)findViewById(R.id.device_query_condition_query);
	spinner1=(Spinner)findViewById(R.id.device_query_condition_devicelistid);
	String[] date=new String[]{"请选择","未巡检","已巡检"};
	ArrayAdapter<String> ada1 = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, date);// 放数据
	ada1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);// 设置打开方式
	spinner.setAdapter(ada1);
	spinner.setOnItemSelectedListener(new OnItemSelectedListener() {

	    @Override
	    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
		devicestatus=parent.getItemAtPosition(position).toString();
		
	    }

	    @Override
	    public void onNothingSelected(AdapterView<?> parent) {
		
		
	    }
	});
	edit2.setOnItemSelectedListener(new OnItemSelectedListener() {

	    @Override
	    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
		deviceType=parent.getItemAtPosition(position).toString();
		System.out.println("-------------"+deviceType);
		
	    }

	    @Override
	    public void onNothingSelected(AdapterView<?> parent) {
		// TODO Auto-generated method stub
		
	    }
	});
	ArrayAdapter<SpinnerVo> ada2 = new ArrayAdapter<SpinnerVo>(this, android.R.layout.simple_spinner_item, dao.queryAllDeviceList());// 放数据
	ada2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);// 设置打开方式
	spinner1.setAdapter(ada2);
	spinner1.setOnItemSelectedListener(new OnItemSelectedListener() {

	    @Override
	    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
		
		
	    }

	    @Override
	    public void onNothingSelected(AdapterView<?> parent) {
		// TODO Auto-generated method stub
		
	    }
	});
	
    }

    @Override
    protected void onDestroy() {
	dao.close();
	super.onDestroy();
    }

    public String getDevicestatus() {
        return devicestatus;
    }

    public void setDevicestatus(String devicestatus) {
        this.devicestatus = devicestatus;
    }

    public String getDeviceType() {
        return deviceType;
    }

    public void setDeviceType(String deviceType) {
        this.deviceType = deviceType;
    }

    public String getDeviceListid() {
        return deviceListid;
    }

    public void setDeviceListid(String deviceListid) {
        this.deviceListid = deviceListid;
    }
    
    
    
    
}
